package com.szqhyxj.youxiangju.biz.equipmentActivation;

import android.text.TextUtils;

import com.google.gson.annotations.SerializedName;
import com.szqhyxj.youxiangju.sys.BaseResult;
import com.szqhyxj.youxiangju.sys.RetrofitFacade;

import io.reactivex.Observable;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;

/**
 * Created by leung on 2018/11/3.
 */

public class EquipmentModel {
    public interface EquipmentService{
        @FormUrlEncoded
        @POST("merchant/net")
        Observable<BaseResult> merchantNet(
                @Field("provCode") String provCode,
                @Field("cityCode") String cityCode,
                @Field("areaCode") String areaCode,
                @Field("detAddress") String detAddress,
                @Field("deviceNo") String deviceNo
        );
    }

    public static Observable<BaseResult> getmerchntNet(EquipmentEntity equipmentEntity){
            return RetrofitFacade.Companion.getRetrofit().create(EquipmentService.class).merchantNet(
                    equipmentEntity.getProvCode(),
                    equipmentEntity.getCityCode(),
                    equipmentEntity.getAreaCode(),
                    equipmentEntity.getDetAddress(),
                    equipmentEntity.getDeviceNo()
            );
    }

    public static class EquipmentEntity{

        @SerializedName("areaCode")
        private String areaCode;

        @SerializedName("provCode")
        private String provCode;

        @SerializedName("cityCode")
        private String cityCode;

        @SerializedName("detAddress")
        private String detAddress;

        @SerializedName("deviceNo")
        private String deviceNo;
        public boolean valid () {
            return !TextUtils.isEmpty(this.areaCode)
                    && !TextUtils.isEmpty(this.detAddress)
                    && !TextUtils.isEmpty(this.provCode)
                    && !TextUtils.isEmpty(this.cityCode)
                    && !TextUtils.isEmpty(this.deviceNo);

        }
        public void setAreaCode(String areaCode){
            this.areaCode = areaCode;
        }

        public String getAreaCode(){
            return areaCode;
        }

        public void setProvCode(String provCode){
            this.provCode = provCode;
        }

        public String getProvCode(){
            return provCode;
        }

        public void setCityCode(String cityCode){
            this.cityCode = cityCode;
        }

        public String getCityCode(){
            return cityCode;
        }

        public void setDetAddress(String detAddress){
            this.detAddress = detAddress;
        }

        public String getDetAddress(){
            return detAddress;
        }

        public void setDeviceNo(String deviceNo){
            this.deviceNo = deviceNo;
        }

        public String getDeviceNo(){
            return deviceNo;
        }

        @Override
         public String toString(){
            return
                "EquipmentEntity{" +
                "areaCode = '" + areaCode + '\'' +
                ",provCode = '" + provCode + '\'' +
                ",cityCode = '" + cityCode + '\'' +
                ",detAddress = '" + detAddress + '\'' +
                ",deviceNo = '" + deviceNo + '\'' +
                "}";
            }
    }
}
